package com.vidmt.api.modules.sys.entity;

import java.util.Date;

import com.alibaba.fastjson.JSONObject;
import com.thinkgem.jeesite.common.persistence.DataEntity;
import com.vidmt.api.common.utils.CommUtil;
import com.vidmt.api.modules.sys.Enums.LvlType;
import com.vidmt.api.modules.sys.Enums.OrderStatus;
import com.vidmt.api.modules.sys.Enums.PayType;
import com.vidmt.api.modules.sys.entity.sub.RoleLvl;
import com.vidmt.api.modules.sys.utils.VUtil;

public class Order extends DataEntity {
	private static final long serialVersionUID = 1L;

	public void genId() {
		this.id = VUtil.time14() + CommUtil.randString(18);
	}

	public void encodeAttach() {
		JSONObject json = new JSONObject();
		json.put("uid", this.getId());
		json.put("lvltype", this.getLvlType());
		this.setAttach(json.toJSONString());
	}

	public static String genSubject(RoleLvl lvl) {
		String subject = "手机号定位:";
		if (lvl.getLvltype() == LvlType.YEAR) {
			subject += "年会员";
		} else if (lvl.getLvltype() == LvlType.TRY) {
			subject += "临时会员(" + lvl.getDuring() / (24 * 60 * 60) + "天)";
		}
		return subject;
	}

	protected String id;
	protected Long uid;
	protected String[] skus;
	protected LvlType lvlType;
	protected String subject;
	protected String attach;
	protected Integer totalFee;
	protected PayType payType;
	protected String tradeNo;
	protected String payAcc;
	// TODO NOT USED
	protected OrderStatus status;
	protected Date payTime;
	protected Date createTime;
	protected Date modifyTime;
	protected Date refundTime;

	public JSONObject toPayinfo() {
		return null;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Long getUid() {
		return uid;
	}

	public void setUid(Long uid) {
		this.uid = uid;
	}

	public LvlType getLvlType() {
		return lvlType;
	}

	public void setLvlType(LvlType lvlType) {
		this.lvlType = lvlType;
	}

	public String getSubject() {
		return subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	public Integer getTotalFee() {
		return totalFee;
	}
	
	public Integer getRealFee(){
		return totalFee;
	}

	public void setTotalFee(Integer totalFee) {
		this.totalFee = totalFee;
	}

	public PayType getPayType() {
		return payType;
	}

	public void setPayType(PayType payType) {
		this.payType = payType;
	}

	public String getTradeNo() {
		return tradeNo;
	}

	public void setTradeNo(String tradeNo) {
		this.tradeNo = tradeNo;
	}

	public String getPayAcc() {
		return payAcc;
	}

	public void setPayAcc(String payAcc) {
		this.payAcc = payAcc;
	}

	public OrderStatus getStatus() {
		return status;
	}

	public void setStatus(OrderStatus status) {
		this.status = status;
	}

	public Date getPayTime() {
		return payTime;
	}

	public void setPayTime(Date payTime) {
		this.payTime = payTime;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Date getModifyTime() {
		return modifyTime;
	}

	public void setModifyTime(Date modifyTime) {
		this.modifyTime = modifyTime;
	}

	public String getAttach() {
		return attach;
	}

	public void setAttach(String attach) {
		this.attach = attach;
	}

	public String[] getSkus() {
		return skus;
	}

	public void setSkus(String[] skus) {
		this.skus = skus;
	}

	public String getSkuStr() {
		if (CommUtil.isEmpty(skus)) {
			return null;
		} else {
			StringBuilder sb = new StringBuilder();
			for (String sku : skus) {
				sb.append(sku).append(",");
			}
			return sb.toString();
		}
	}

	public void setSkuStr(String skustr) {
		if (!CommUtil.isEmpty(skustr)) {
			String[] skuarr = skustr.split(",");
			this.skus = skuarr;
		}
	}

	public Date getRefundTime() {
		return refundTime;
	}

	public void setRefundTime(Date refundTime) {
		this.refundTime = refundTime;
	}
}
